﻿// Please see documentation at https://learn.microsoft.com/aspnet/core/client-side/bundling-and-minification
// for details on configuring this project to bundle and minify static web assets.

// Write your JavaScript code.
function customAlert(response, callback) {
    let { code, message } = response;
    if (code == 200)
      $("#customAlertBody").html(
        `<i class="bi bi-check-circle text-success display-6"></i>&nbsp;&nbsp;${message}`
      );
    else
      $("#customAlertBody").html(
        `<i class="bi bi-x-circle text-danger display-6"></i>&nbsp;&nbsp;${message}`
      );
    const modal = new bootstrap.Modal(
      document.getElementById("customAlertModal")
    );
  
    // 移除之前的事件监听器，避免重复绑定
    $("#customAlertModal").off("hidden.bs.modal");
  
    // 显示模态框
    modal.show();
  
    // 设置回调函数
    if (typeof callback === "function") {
      $("#customAlertModal").on("hidden.bs.modal", function () {
        callback();
      });
    }
  }

  function customConfirm(message, callback) {
    $("#customConfirmBody").html(
      `<i class="bi bi-question-circle display-6 text-warning"></i>&nbsp;&nbsp;${message}`
    );
  
    const modal = new bootstrap.Modal(
      document.getElementById("customConfirmModal")
    );
  
    // 移除之前的事件监听器，避免重复绑定
    $("#btnConfirmYes").off("click");
  
    modal.show();
  
    // 设置回调函数
    if (typeof callback === "function") {
      $("#btnConfirmYes").on("click", function () {
        callback();
      });
    }
  }
  
